<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/24
 * 创建任务
 */
namespace app\job\controller;

use think\Controller;
use think\Image;
use think\Queue;

class JobTest extends Controller{
    public function HelloJob(){
        $jobClassName = 'app\job\Hello'; //消费名称
        $jobQueueName = 'helloJobQueue';
        $jobData      = array(
            'ts'    => time(),
            'bizId' => uniqid(),
            'a'     => 1
        );
        //将任务推送到消息队列
        $isPushed=Queue::push($jobClassName, $jobData, $jobQueueName);
        //$isPushed = queue($jobClassName, $jobData,5, $jobQueueName);
        //$isPushed = \think\Queue::push($jobClassName, $jobData, $jobQueueName);
        // database 驱动时，返回值为 1|false  ;   redis 驱动时，返回值为 随机字符串|false
        if($isPushed !== false){
            echo date('Y-m-d H:i:s') . " a new Hello Job is Pushed to the MQ,任务进入队列" . "<br>";
        }else{
            echo 'Oops, something went wrong.';
        }
    }

}
